<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function def(obj, key, val, enumerable) {
            Object.defineProperty(obj, key, {
                value: val,
                enumerable: !!enumerable,
                writable: true,
                configurable: true
            })
        }
        const arrayProto = Array.prototype
        const arrayMethods = Object.create(arrayProto)
        console.log(arrayProto);
        console.log(arrayMethods);

        // console.log(arrayMethods.__proto__===arrayProto);
        const methodsToPatch = [
            'push',
            'pop',
            'shift',
            'unshift',
            'splice',
            'sort',
            'reverse'
        ]

        /**
         * Intercept mutating methods and emit events
         */
        methodsToPatch.forEach(function(method) {
            // cache original method
            const original = arrayProto[method]
            def(arrayMethods, method, function mutator(...args) {
                const result = original.apply(this, args)
                console.log(args);
                return result
            })
        })
        let arr = []
        arr.__proto__ = arrayMethods
        arr.push(5)

        console.log(arr);

    </script>
</body>

</html>